import java.util.Arrays;

public class Solution1781 {
    public int beautySum(String s) {
        int ans=0;
        for (int i=0;i<s.length();i++){
            int[] f=new int[26];
            for (int j=i;j<s.length();j++){
                f[s.charAt(j)-'a']++;
                int min= Arrays.stream(f).max().getAsInt(),max=1;
                for (int i1 = 0; i1 < 26; i1++) {
                    if (f[i1]>0){
                        min=Math.min(min,f[i1]);
                    }
                    max=Math.max(max,f[i1]);
                }
                ans+=max-min;
            }
        }
        return ans;
    }

    public static void main(String[] args) {
        System.out.println(new Solution1781().beautySum("aabcb"));
    }
}
